function listenZoom(map, zoom) {
	google.maps.Event.addListener(map, "zoomend", function () {
		document.getElementById(zoom).value = map.getZoom();
	});
}
function listenMove(map, lng, lat) {
	GEvent.addListener(map, "mousemove", function(point){
		lastPoint = point;
	});
}
function listenClick(map,lng,lat) {
	google.maps.Event.addListener(map, "click", function (marker, point) {
		if (marker) {
			map.removeOverlay(marker);
		} else {
			var icon = createDefaultIcon();
			markerOptions = { icon:icon };
			map.clearOverlays();
			map.addOverlay(new google.maps.Marker(new google.maps.LatLng(lastPoint.lat(), lastPoint.lng()),markerOptions));
			document.getElementById(lng).value = lastPoint.lng();
			document.getElementById(lat).value = lastPoint.lat();
			map.setCenter(new google.maps.LatLng(lastPoint.lat(), lastPoint.lng()));
		}
	});
}

function createDefaultIcon(){
	var icon = new google.maps.Icon();
	icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icon.iconSize = new google.maps.Size(13, 22);
	icon.shadowSize = new google.maps.Size(22, 22);
	icon.iconAnchor = new google.maps.Point(6,20);
	icon.infoWindowAnchor = new google.maps.Point(5, 1);
	return icon;
}

function setMarkerWithIcon(map,lng,lat,iconColor,text){
	var icon = new google.maps.Icon();
	icon.image = "http://labs.google.com/ridefinder/images/mm_20_" + iconColor + ".png";
	icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icon.iconSize = new google.maps.Size(13, 22);
	icon.shadowSize = new google.maps.Size(22, 22);
	icon.iconAnchor = new google.maps.Point(6,20);
	icon.infoWindowAnchor = new google.maps.Point(5, 1);
	markerOptions = { icon:icon };
	var marker = new google.maps.Marker(new google.maps.LatLng(lat,lng),markerOptions);
	GEvent.addListener(marker, "mouseover", function() {
		  marker.openInfoWindowHtml(text);
	});
	map.addOverlay(marker);
}


function showLocation(location) {
  var geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    location + ', Hrvatska',
    function(point) {
      if (!point) {
        alert(location + " not found");
      } else {
        //setMarkerWithIcon(#{gmapVar}, point.lng,point.lat);
        map.setCenter(point, 13);
        var marker = new GMarker(point);

        map.addOverlay(marker);
        //marker.openInfoWindowHtml(location);
      }
    }
  );
}
